#include "commandLineParser.h"

#include <iostream>


CCommandLineParser::CCommandLineParser():m_optDesc("rawconvertor --input <input folder> [--output <output folder>]\n Allowed options")
{
    m_optDesc.add_options()
            ("help", "produce help message")
            ("input", po::value<tstring>(), "Folder witch consists images in .NEF format. Input folder is mandatory parameter!")
            ("output", po::value<tstring>(), "Folder where images will be saved after converting. Output folder is optional parameter.")                
    ;
    
}

void CCommandLineParser::printHelp() const
{
    std::cout << m_optDesc << "\n";
}

bool CCommandLineParser::parseCommandLine(int argc, char** argv)
{
    

    po::variables_map vm;        
    po::store(po::parse_command_line(argc, argv, m_optDesc), vm);
    po::notify(vm);    

    if (vm.count("help"))
    {
        printHelp();
        return false;
    }

    if (vm.count("input"))
    {
        std::cout << "Input folder was set to "<< vm["input"].as<tstring>() << ".\n";
        m_strInputFoldef = vm["input"].as<tstring>();
    }
    else
    {
       //std::cout << "Input folder was not set.\n";
        throw std::runtime_error("Input folder was not set.\n");
    }
        
    if (vm.count("output"))
    {
        std::cout << "Output folder was set to  "<< vm["output"].as<tstring>() << ".\n";
        m_strOutputFolder = vm["output"].as<tstring>();
    }
    else
    {
        //std::cout << "Output folder was not set.\n";
        m_strOutputFolder = m_strInputFoldef;
    }
    return true;
}